import 'package:easy_refresh/easy_refresh.dart';
import 'package:situation/app/theme/app_theme.dart';
import 'package:situation/app/theme/gaps.dart';
import 'package:situation/data/store/config_store.dart';
import 'package:situation/shared/util/util_mk.dart';
import 'package:situation/widgets/PlayVideo.dart';
import 'package:situation/widgets/app/app_intell.dart';
import 'package:situation/widgets/mk_load_image.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';

import 'controller.dart';

class IntelHistoryPage extends StatefulWidget {
  const IntelHistoryPage({Key? key}) : super(key: key);

  @override
  State<IntelHistoryPage> createState() => _IntelHistoryPageState();
}

class _IntelHistoryPageState extends State<IntelHistoryPage> {
  final controller = Get.find<IntelHistoryController>();
  final state = Get.find<IntelHistoryController>().state;

  @override
  Widget build(BuildContext context) {
    return Scaffold(appBar: TDNavBar(title: '我报知的情报'), body: _buildBody());
  }

  _buildBody() {
    return Obx(
      () => EasyRefresh(
        // 下拉样式
        header: TDRefreshHeader(),
        child: ListView.builder(
          itemCount: state.intellHistory.length,
          itemBuilder: itemBuilder,
        ),
        // 下拉刷新回调
        onRefresh: controller.onRefresh,
      ),
    );
  }

  @override
  void dispose() {
    Get.delete<IntelHistoryController>();
    super.dispose();
  }

  Widget? itemBuilder(BuildContext context, int index) {
    return GestureDetector(
      onTap: () {
        controller.toDetail(index);
      },
      child: AppIntell(intell: state.intellHistory[index]),
    );
  }

}
